package com.witframework.web.extremetable;

import java.lang.reflect.Field;

import org.extremecomponents.table.core.TableModel;
import org.extremecomponents.util.HtmlBuilder;


/**
 * 新的信息提示区
 * 在工具区的左边显示提示信息或错误信息
 * @author wuxinyang
 *
 */
public class WsMessageBarBuilder {
    private HtmlBuilder html;
    private TableModel model;

    public WsMessageBarBuilder(TableModel model) {
        this(new HtmlBuilder(), model);
    }
    
    public WsMessageBarBuilder(HtmlBuilder html, TableModel model) {
        this.html = html;
        this.model = model;
    }

    public HtmlBuilder getHtmlBuilder() {
        return html;
    }

    protected TableModel getTableModel() {
        return model;
    }

    public void statusMessage() {  
    		String id=model.getTableHandler().getTable().getTableId();
    		String title=model.getTableHandler().getTable().getTitle();    		
    		
    		if(title==null||title.equals("null"))title="";    		
    		html.bold();
//			html.append(title).nbsp().nbsp();
    		//将操作按钮显示到ec title 位置
    		html.append("<span id=\"optbar_"+model.getTableHandler().getTable().getTableId()+"\"></span><script>try{document.getElementById('optbar_"+id+"').innerHTML=document.getElementById('optbar').innerHTML;document.getElementById('optbar_"+id+"').className=document.getElementById('optbar').className;document.getElementById('optbar').style.display='none';}catch(exception){}</script>");
			html.boldEnd();
		
    }
    
    public String toString() {
        return html.toString();
    }
    /**
     * 获取当前类声明的private/protected变量
     */
    static public Object getPrivateProperty(Object object, String propertyName) throws IllegalAccessException, NoSuchFieldException {
    
        Field field = object.getClass().getDeclaredField(propertyName);
        field.setAccessible(true);
        return field.get(object);
    }
}
